package com.wars2d.client;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.backends.jogl.JoglApplication;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.tiled.SimpleTileAtlas;
import com.badlogic.gdx.graphics.g2d.tiled.TileAtlas;
import com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer;
import com.badlogic.gdx.graphics.g2d.tiled.TileSet;
import com.badlogic.gdx.graphics.g2d.tiled.TiledLoader;
import com.badlogic.gdx.graphics.g2d.tiled.TiledMap;
import com.badlogic.gdx.graphics.g2d.tiled.TiledObject;

public class MainRenderer implements ApplicationListener {
	
	public static void main(String[] args) {
		new JoglApplication(new MainRenderer(), "blah blah", 640, 480, false);
	}

	TileMapRenderer mRenderer;
	
	OrthographicCamera mCamera = null;
	
	@Override
	public void create() {
		TiledMap map = TiledLoader.createMap(Gdx.files.internal("data/map.tmx"));
		
		TileAtlas mTiles = new SimpleTileAtlas(map, Gdx.files.internal("data/"));
		
		TiledObject object = new TiledObject();
		
		mRenderer = new TileMapRenderer(map, mTiles, 1, 1);
		
		mCamera = new OrthographicCamera(640, 480);
		mCamera.position.x = 320;
		mCamera.position.y = 240;
	}

	@Override
	public void dispose() {
		
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void render() {
		Gdx.gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		mCamera.update();
		mRenderer.render(mCamera);
		
		if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) {
			mCamera.position.x += 10;
		} else if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) {
			mCamera.position.x -= 10;
		} else if (Gdx.input.isKeyPressed(Keys.DPAD_DOWN)) {
			mCamera.position.y -= 10;
		} else if (Gdx.input.isKeyPressed(Keys.DPAD_UP)) {
			mCamera.position.y += 10;
		}
	}

	@Override
	public void resize(int arg0, int arg1) {
		
	}

	@Override
	public void resume() {
		
	}
}
